Overview
The basic usage example showcases:- Key generation and parameter setup
- Encryption and decryption of values
- Homomorphic addition, multiplication, and subtraction
- Algebraic properties (commutativity, associativity, distributivity)
- Advanced operations (powers, polynomials, Fibonacci, factorial)
- Text encryption and performance benchmarks
Key generation
1
Initialize parameters and keys
Start by setting up the cryptographic parameters and generating the public/secret key pair:This creates default parameters with:
m_bits: Field size parametern_bits: Security parameterB: Budget parameter
Basic encryption and decryption
Encrypt and decrypt integer values:The
.lo field extracts the lower 64 bits of the field element, which contains the encrypted integer value.Homomorphic operations
Addition and subtraction
Multiplication
Algebraic properties
PVAC-HFHE preserves standard algebraic properties:Commutativity
Associativity
Distributivity
Advanced examples
Computing powers
Compute x^8 through repeated squaring:Fibonacci sequence
Compute the 10th Fibonacci number:Factorial
Compute 6! homomorphically:Sum of squares
Compute 1² + 2² + 3² + 4² + 5²:Text encryption
PVAC-HFHE supports encrypting text strings:Ciphertext properties
Randomized encryption
The same plaintext encrypted twice produces different ciphertexts:Commitments
Generate cryptographic commitments to ciphertexts:Commitments bind to specific ciphertexts and can be used for verifiable computation protocols.
Complete example
Here’s a complete working example:Source code
The complete basic usage example with all test cases is available at:examples/basic_usage.cpp
Next steps
Polynomial evaluation
Learn how to evaluate polynomials homomorphically
ML credit scoring
Build encrypted machine learning models